using System.Collections.Generic;
using Token = TBit.Compile.ASMCompile.Token;
using TBit.Compile;

namespace TBit.Instrcutions {
    public static class Not {
        public static int Compile(List<Token> tokens,VM vm,int i) {
            return ASMCompile.StructureInstruction_OPCODE_R_R(Opcode.NOT,tokens,vm,i);
        }
        public static Instruction Create(RegisterIndex a,RegisterIndex b) {
            Instruction inst = new Instruction();
            inst.opcode = Opcode.NOT;
            inst.args.Add(new InstructionArgData(a));
            inst.args.Add(new InstructionArgData(b));
            return inst;
        }

        public static Data Calc(Data a) {
            Data data = new Data();
            if(a.type == DataType.Boolean)
            {
                data.type = DataType.Boolean;
                data.boolean_data = !a.boolean_data;
            }
            return data;
        }

        public static int Run(VM vm,Instruction inst){
            InstructionArgData arg1 = inst.args[0];
            InstructionArgData arg2 = inst.args[1];
            Data a = vm.GetRegister(arg1.register);
            Data v = Calc(a);
            vm.WriteRegister(arg2.register,v);
            return 1;
        }
    }
}